﻿using Chain.BLL;
using Chain.Model;
//using ChainStock.WebReference;
using System;
using System.Data;
using System.Text;

public partial class SMSInfo
{
    private static SmsService SMS = new SmsService();

    public static string GetBalance(bool smsType)
    {
        string strBalance = "0";
        string name, pwd;
        Chain.BLL.SysParameter SysParameterdll = new Chain.BLL.SysParameter();
        DataSet ds = SysParameterdll.GetList(" ParameterID=1");

        try
        {
            if (smsType)
            {
                name = ds.Tables[0].Rows[0]["MarketingSmsSeries"].ToString();
                pwd = ds.Tables[0].Rows[0]["MarketingSmsSerialPwd"].ToString();
                return  WebTest.SendMessage.GetBalance(name, pwd);
            }
            name = ds.Tables[0].Rows[0]["SmsSeries"].ToString();
            pwd = ds.Tables[0].Rows[0]["SmsSerialPwd"].ToString();
            strBalance= WebTest.SendMessage.GetBalance(name, pwd);
        }
        catch
        {
        }
        return strBalance;
    }
    public static string GetSendContent_new(string strSendContent, SmsTemplateParameter smsTemplateParameter, int intShopID)
    {
        Chain.BLL.SmsTemplate bllTemplate = new Chain.BLL.SmsTemplate();
        Chain.Model.SmsTemplate modelTemplate = new Chain.Model.SmsTemplate();
        
        StringBuilder strTemplateContent = new StringBuilder(strSendContent);
        strTemplateContent.Replace("{CardID}", smsTemplateParameter.strCardID);
        strTemplateContent.Replace("{LCardID}", smsTemplateParameter.strCardID.Substring(smsTemplateParameter.strCardID.Length - 3));
        strTemplateContent.Replace("{Name}", smsTemplateParameter.strName);
        strTemplateContent.Replace("{TempMoney}", smsTemplateParameter.dclTempMoney.ToString("0.00"));
        strTemplateContent.Replace("{Money}", smsTemplateParameter.dclMoney.ToString("0.00"));
        strTemplateContent.Replace("{Time}", DateTime.Now.ToString("yy年MM月dd日HH时mm分"));
        strTemplateContent.Replace("{TempPoint}", smsTemplateParameter.intTempPoint.ToString());
        strTemplateContent.Replace("{Point}", smsTemplateParameter.intPoint.ToString());
        Chain.BLL.MemLevel bllMemLevel = new Chain.BLL.MemLevel();
        Chain.Model.MemLevel modelMemLevel = new Chain.Model.MemLevel();
        modelMemLevel = bllMemLevel.GetModel(smsTemplateParameter.OldLevelID);
        strTemplateContent.Replace("{OldLevel}", modelMemLevel.LevelName);
        modelMemLevel = bllMemLevel.GetModel(smsTemplateParameter.NewLevelID);
        strTemplateContent.Replace("{NewLevel}", modelMemLevel.LevelName);
        strTemplateContent.Replace("{MemBirthday}", string.Format("{0}月{1}日", Convert.ToInt32(smsTemplateParameter.MemBirthday.ToString("MM")), Convert.ToInt32(smsTemplateParameter.MemBirthday.ToString("dd"))));
        strTemplateContent.Replace("{MemPastTime}", smsTemplateParameter.MemPastTime.ToString("yyyy-MM-dd"));
        strTemplateContent.Replace("{TempGoodsItem}", smsTemplateParameter.CountItemsString);
        return strTemplateContent.ToString();
    }
    public static string GetSendContent(int intTemplateType, SmsTemplateParameter smsTemplateParameter, int intShopID)
    {
        Chain.BLL.SmsTemplate bllTemplate = new Chain.BLL.SmsTemplate();
        Chain.Model.SmsTemplate modelTemplate = new Chain.Model.SmsTemplate();
        modelTemplate = bllTemplate.GetModel(intTemplateType);
        StringBuilder strTemplateContent = new StringBuilder(modelTemplate.TemplateContent);
        strTemplateContent.Replace("{CardID}", smsTemplateParameter.strCardID);
        strTemplateContent.Replace("{LCardID}", smsTemplateParameter.strCardID.Substring(smsTemplateParameter.strCardID.Length - 3));
        strTemplateContent.Replace("{Name}", smsTemplateParameter.strName);
        strTemplateContent.Replace("{TempMoney}", smsTemplateParameter.dclTempMoney.ToString("0.00"));
        strTemplateContent.Replace("{Money}", smsTemplateParameter.dclMoney.ToString("0.00"));
        strTemplateContent.Replace("{Time}", DateTime.Now.ToString("yy年MM月dd日HH时mm分"));
        strTemplateContent.Replace("{TempPoint}", smsTemplateParameter.intTempPoint.ToString());
        strTemplateContent.Replace("{Point}", smsTemplateParameter.intPoint.ToString());
        Chain.BLL.MemLevel bllMemLevel = new Chain.BLL.MemLevel();
        Chain.Model.MemLevel modelMemLevel = new Chain.Model.MemLevel();
        modelMemLevel = bllMemLevel.GetModel(smsTemplateParameter.OldLevelID);
        strTemplateContent.Replace("{OldLevel}", modelMemLevel.LevelName);
        modelMemLevel = bllMemLevel.GetModel(smsTemplateParameter.NewLevelID);
        strTemplateContent.Replace("{NewLevel}", modelMemLevel.LevelName);
        strTemplateContent.Replace("{MemBirthday}", string.Format("{0}月{1}日", Convert.ToInt32(smsTemplateParameter.MemBirthday.ToString("MM")), Convert.ToInt32(smsTemplateParameter.MemBirthday.ToString("dd"))));
        strTemplateContent.Replace("{MemPastTime}", smsTemplateParameter.MemPastTime.ToString("yyyy-MM-dd"));
        strTemplateContent.Replace("{TempGoodsItem}", smsTemplateParameter.CountItemsString);
        if (modelTemplate.TemplateID < 13)
        {
            if (PubFunction.curParameter.bolIsSmsShopName)
            {
                if (PubFunction.curParameter.strSmsShopName != "")
                {
                    strTemplateContent.Append("【" + PubFunction.curParameter.strSmsShopName + "】");
                }
            }
            else
            {
                Chain.BLL.SysShop bllShop = new Chain.BLL.SysShop();
                Chain.Model.SysShop modelShop = new Chain.Model.SysShop();
                modelShop = bllShop.GetModel(intShopID);
                if (modelShop.ShopSmsName != "")
                {
                    strTemplateContent.Append("【" + modelShop.ShopSmsName + "】");
                }
            }
        }
        return strTemplateContent.ToString();
    }

    public static bool Send_GXSMS(bool SmsType, string MobileList, string Content, string Stime)
    {
        long startTime = DateTime.Now.Ticks;

        bool result = false;
        if (SmsType)
        {
            result = WebTest.SendMessage.SendSMS(intMarketingSMS.ToString(), strMarketingSmsSeries, strMarketingSmsSerialPwd, MobileList, Content, Stime);


        }
        else
        {
            result = WebTest.SendMessage.SendSMS(intNotificationSMS.ToString(), strNotificationSMS, strNotificationSMSPwd, MobileList, Content, Stime);
        }
        new TimeSpan(DateTime.Now.Ticks - startTime);
        return result;
    }

    public static bool Send_SMS(bool SmsType, string MobileList, string Content, string Stime)
    {
        long startTime = DateTime.Now.Ticks;
      
        bool result = false;
        if (SmsType)
        {
            result = WebTest.SendMessage.SendSMS(intMarketingSMS.ToString(), strMarketingSmsSeries, strMarketingSmsSerialPwd, MobileList, Content, Stime);
                
              
        }
        else
        {
            result = WebTest.SendMessage.SendSMS(intNotificationSMS.ToString(), strNotificationSMS, strNotificationSMSPwd, MobileList, Content, Stime);
        }
        new TimeSpan(DateTime.Now.Ticks - startTime);
        return result;
    }

    private static int intMarketingSMS
    {
        get
        {
            return PubFunction.curParameter.intMarketingSMS;
        }
    }

    private static int intNotificationSMS
    {
        get
        {
            return PubFunction.curParameter.intNotificationSMS;
        }
    }

    private static string strMarketingSmsSerialPwd
    {
        get
        {
            return PubFunction.curParameter.strMarketingSmsSerialPwd;
        }
    }

    private static string strMarketingSmsSeries
    {
        get
        {
            return PubFunction.curParameter.strMarketingSmsSeries;
        }
    }

    private static string strNotificationSMS
    {
        get
        {
            return PubFunction.curParameter.strNotificationSMS;
        }
    }

    private static string strNotificationSMSPwd
    {
        get
        {
            return PubFunction.curParameter.strNotificationSMSPwd;
        }
    }
}

